package org.tulkas.web;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tulkas.config.GlobalConfig;

/**
 * @author <a href="mailto:tulkas.web@gmail.com">Tulkas</a>
 *
 */
public class ContextInitListener implements ServletContextListener {

	/* (non-Javadoc)
	 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
	 */
	public void contextDestroyed(ServletContextEvent sce) {
		Logger logger = LoggerFactory.getLogger(ContextInitListener.class);
		logger.info("Tulkas Robot destroying.");
	}

	/* (non-Javadoc)
	 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
	 */
	public void contextInitialized(ServletContextEvent sce) {
		String homePath = sce.getServletContext().getInitParameter(
				"tulkas.home");
		if (homePath != null) {
			GlobalConfig.init(homePath);
		}

		Logger logger = LoggerFactory.getLogger(ContextInitListener.class);
		logger.info("Tulkas Robot initialization begin.");
//		try {
//			PersistenceHelper.initDerbyDriver();
//			LogManager.getInstance().init();
//		} catch (Exception e) {
//			logger.error("Initialization Error. []" + e.getMessage(), e);
//		}
	}

}
